home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cug236
/
bawk.h
< prev
next >
Wrap
Text File
|
1980-01-02
|
8KB
|
296 lines
/*
HEADER: CUG000.00;
TITLE: BAWK Include File;
DATE: 05/17/1987;
VERSION: 1.1;
FILENAME: BAWK.H;
SEE-ALSO: BAWK.C;
AUTHORS: W. C. Colley III, B. Brodt;
*/
/*
* Shortened names of variables Fieldsep and Recordsep to keep them unique
* in their first six characters so that compilers with limited external
* name widths like Eco-C (CP/M version) don't choke. Fixed minor glitch
* that causes some compilers to choke on function str_compile(). Added a few
* portability notes for some odd compilers. Dealt with side effects of
* tolower() implemented as a macro. Leaned on the host compiler's library
* for is....() functions. Stripped BDS C hooks and some ugly hacks that
* they required. Removed the dependency on sizeof(int) == sizeof(char *).
* 16 MAY 1987. William C. Colley, III.
*/
/*
* Portability Note: 8-bit systems often don't have the header files ctype.h
* and string.h. If your compiler is one of these animals, uncomment the
* following #defines as required.
*/
/*
#define NO_CTYPE_H
#define NO_STRING_H
*/
/*
* Portability Note: Back in K & R days, standard library function malloc()
* was called alloc(). Some compilers (e.g. Eco-C under CP/M) haven't made
* the name change. If yours is one of these compilers, uncomment the
* following #define:
*/
/*
#define malloc(p) alloc(p)
*/
/*
* Portability Note: The AZTEC C compilers handle the binary/text file
* dichotomy differently from most other compilers. Uncomment the following
* pair of #defines if you are running AZTEC C:
*/
/*
#define getc(f) agetc(f)
#define putc(c,f) aputc(c,f)
*/
#ifdef NO_CTYPE_H
int isalnum(), isalpha(), isdigit(), tolower();
#else
#include <ctype.h>
#endif
#ifdef NO_STRING_H
int strncmp(), strlen();
#else
#include <string.h>
#endif
/*
* Bawk constants and variable declarations.
*/
#ifdef BDS_C
#define EXTERN /* */
#else
#ifdef MAIN
#define EXTERN /* */
#else
#define EXTERN extern
#endif
#endif
#define DEBUG 1 /* remove this line to compile without debug statements */
#ifdef DEBUG
EXTERN char Debug; /* debug print flag */
#endif
/*
* Table and buffer sizes
*/
#define MAXLINELEN 128 /* longest input line */
#define MAXWORDS (MAXLINELEN/2) /* max # of words in a line */
#define MAXWORKBUFLEN 4096 /* longest action or regular expression */
#define MAXVARTABSZ 50 /* max # of symbols */
#define MAXVARLEN 10 /* symbol name length */
#define MAXSTACKSZ 40 /* max value stack length (for expressions) */
/**********************************************************
* Current Input File variables *
**********************************************************/
/*
* Current Input File pointer:
*/
EXTERN FILE *Fileptr;
EXTERN char *Filename; /* current input file name */
EXTERN int Linecount; /* current input line number */
EXTERN int Recordcount; /* record count */
/*
* Working buffers.
*/
EXTERN char Linebuf[ MAXLINELEN ]; /* current input line buffer */
EXTERN char *Fields[ MAXWORDS ]; /* pointers to the words in Linebuf */
EXTERN int Fieldcount; /* and the # of words */
EXTERN char Workbuf[ MAXWORKBUFLEN ]; /* work area for C action and */
/* regular expression parsers */
/**********************************************************
* Regular Expression Parser variables *
**********************************************************/
/*
* Tokens:
*/
#define CHAR 1
#define BOL 2
#define EOL 3
#define ANY 4
#define CLASS 5
#define NCLASS 6
#define STAR 7
#define PLUS 8
#define MINUS 9
#define ALPHA 10
#define DIGIT 11
#define NALPHA 12
#define PUNCT 13
#define RANGE 14
#define ENDPAT 15
/**********************************************************
* C Actions Interpreter variables *
**********************************************************/
/*
* Tokens:
*/
#define T_STRING 'S' /* primaries: */
#define T_DOLLAR '$'
#define T_REGEXP 'r'
#define T_CONSTANT 'C'
#define T_VARIABLE 'V'
#define T_FUNCTION 'F'
#define T_SEMICOLON ';' /* punctuation */
#define T_EOF 'Z'
#define T_LBRACE '{'
#define T_RBRACE '}'
#define T_LPAREN '('
#define T_RPAREN ')'
#define T_LBRACKET '['
#define T_RBRACKET ']'
#define T_COMMA ','
#define T_ASSIGN '=' /* operators: */
#define T_MUL '*'
#define T_DIV '/'
#define T_MOD '%'
#define T_ADD '+'
#define T_SUB '-'
#define T_SHL 'L'
#define T_SHR 'R'
#define T_LT '<'
#define T_LE 'l'
#define T_GT '>'
#define T_GE 'g'
#define T_EQ 'q'
#define T_NE 'n'
#define T_NOT '~'
#define T_AND '&'
#define T_XOR '^'
#define T_IOR '|'
#define T_LNOT '!'
#define T_LAND 'a'
#define T_LIOR 'o'
#define T_INCR 'p'
#define T_DECR 'm'
#define T_IF 'i' /* keywords: */
#define T_ELSE 'e'
#define T_WHILE 'w'
#define T_BREAK 'b'
#define T_CHAR 'c'
#define T_INT 't'
#define T_BEGIN 'B'
#define T_END 'E'
#define T_NF 'f'
#define T_NR '#'
#define T_FS ' '
#define T_RS '\n'
#define T_FILENAME 'z'
#define PATTERN 'P' /* indicates C statement is within a pattern */
#define ACTION 'A' /* indicates C statement is within an action */
/*
* Symbol table
*/
typedef struct variable {
char vname[ MAXVARLEN ];
char vclass;
char vsize;
int vlen;
char *vptr;
} VARIABLE;
EXTERN VARIABLE Vartab[ MAXVARTABSZ ], *Nextvar;
/*
* Value stack
*/
typedef union datum {
int ival;
char *dptr;
char **ptrptr;
} DATUM;
typedef struct item {
char class;
char lvalue;
char size;
DATUM value;
} ITEM;
EXTERN ITEM Stackbtm[ MAXSTACKSZ ], *Stackptr, *Stacktop;
/*
* Symbol Table values
*/
#define ACTUAL 0
#define LVALUE 1
#define BYTE 1
#define WORD sizeof(DATUM)
/*
* Miscellaneous
*/
EXTERN char *Actptr; /* pointer into Workbuf during compilation */
EXTERN char Token; /* current input token */
EXTERN DATUM Value; /* and its value */
EXTERN char Saw_break; /* set when break stmt seen */
EXTERN char Where; /* indicates whether C stmt is a PATTERN or ACTION */
EXTERN char Fldsep[3]; /* field seperator */
EXTERN char Rcrdsep[3]; /* record seperator */
EXTERN char *Beginact; /* BEGINning of input actions */
EXTERN char *Endact; /* END of input actions */
/**********************************************************
* Rules structure *
**********************************************************/
typedef struct rule {
struct {
char *start; /* C statements that match pattern start */
char *stop; /* C statements that match pattern end */
char startseen; /* set if both a start and stop pattern */
/* given and if an input line matched the */
/* start pattern */
} pattern;
char *action; /* contains quasi-C statements of actions */
struct rule *nextrule; /* pointer to next rule */
} RULE;
EXTERN RULE *Rules, /* rule structures linked list head */
*Rulep; /* working pointer */
/**********************************************************
* Miscellaneous *
**********************************************************/
/*
* Error exit values (returned to command shell)
*/
#define USAGE_ERROR 1 /* error in invokation */
#define FILE_ERROR 2 /* file not found errors */
#define RE_ERROR 3 /* bad regular expression */
#define ACT_ERROR 4 /* bad C action stmt */
#define MEM_ERROR 5 /* out of memory errors */
/*
* Functions that are referenced across module boundaries:
*/
char *getmem(), *malloc();
int act_compile(), alpha(), alphanum(), atoi(), dopattern(), getcharacter();
int getline(), getoken(), instr(), isfunction(), iskeyword(), match();
int parse(), pat_compile(), pop(), popint(), re_compile(), ungetcharacter();
VARIABLE *findvar(), *addvar(), *decl();
void assignment(), declist(), doaction(), endfile(), error(), expression();
void fillmem(), free(), function(), movemem(), push(), pushint();
void syntaxerror(), unparse();